package com.zzh.StudentManagementSystem;



import java.util.ArrayList;

public class ArrayListStudent {



        private ArrayList<Student1> students = new ArrayList<>();

        // 添加学生
        public void addStudent(Student1 student) {

            students.add(student);
            System.out.println("学生添加成功！");
        }


        // 删除学生
        public void deleteStudent(String id) {
            for (Student1 student : students) {
                if (student.getId().equals(id)) {
                    students.remove(student);
                    System.out.println("学生删除成功！");
                    return;
                }
            }
            System.out.println("未找到该学生！");
        }

        // 修改学生信息
        public void updateStudent(String id, String newName, int newAge,String newAddress) {
            for (Student1 student : students) {
                if (student.getId().equals(id)) {
                    student.setName(newName);
                    student.setAge(newAge);
                    student.setAddress(newAddress);
                    System.out.println("学生信息修改成功！");
                    return;
                }
            }
            System.out.println("未找到该学生！");
        }

        // 查询学生（按学号）
        public void findStudentById(String id) {
            for (Student1 student : students) {
                if (student.getId().equals(id)) {
                    System.out.println(student);
                    return;
                }
            }
            System.out.println("未找到该学生！");
        }
        public int getIndex(String id) {
            for (Student1 student : students) {
                if (student.getId().equals(id)) {
                    return 1;
                }
            }
            return -1;
        }

        // 显示所有学生
        public void displayAllStudents() {
            if (students.isEmpty()) {
                System.out.println("当前没有学生信息！");
                return;
            }
            System.out.println("==================== 学生列表 ====================");
            for (Student1 student : students) {
                System.out.println(student);
            }
        }

    }

